<template>
  <div class="home">
    <TopNav/>
    <div class="title">
      <img src="../assets/image/logo_urbanplate.svg" alt="">
      <h2>Modern, delicious and creative vego food. <br>
        This isn’t your usual vegetarian site.</h2>
    </div>
    <div class="container">
      <FoodBox
        v-for="(food, index) in allFoods"
        :key="food.id"
        :food="food"
        :class="{ 'first-item': index === 0 }"
      />
    </div>
    <Footer/>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useStore } from 'vuex'
import TopNav from '@/components/TopNav.vue'
import FoodBox from '@/components/FoodBox.vue'
import Footer from '@/components/FooterIndex.vue'

// 使用 useStore 钩子访问 Vuex store
const store = useStore()

// 使用 computed 计算属性来访问 Vuex store 中的 getters
const allFoods = computed(() => store.getters.allFoods)
</script>

<style lang="scss" scoped>
.title{
  display: flex;
  justify-content: center;
  align-items: center;

  img{
    width: 150px;
    transition: transform 0.3s ease;

    &:hover{
      transform: rotate(15deg);
    }
  }

  h2{
    color: #000000;
    width: calc(56vw);
    line-height: 36px;
    padding: 20px;
    font-size: 32px;
    text-align: left;
    font-weight: normal;

    @media (max-width: 768px) {
      width: 80%;
      font-size: 16px;
      text-align: center;
    }
  }

  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.container {
  padding: 0 20px;
  margin: 100px auto;
  display: grid;
  grid-gap: 10px;
  grid-template-columns: repeat(5, 1fr);

  @media (max-width: 1200px) {
    grid-template-columns: repeat(3, 1fr);
  }

  @media (max-width: 768px) {
    grid-template-columns: repeat(2, 1fr);
    margin: 50px auto;
  }

  @media (max-width: 480px) {
    grid-template-columns: repeat(1, 1fr);
  }
}

.first-item {
  grid-column: span 2; // 在大屏幕上占据 2 列
  grid-row: span 2;    // 在大屏幕上占据 2 行
}

@media (max-width: 768px) {
  .first-item {
    grid-column: span 1; // 在小屏幕上恢复占据 1 列
    grid-row: span 1;     // 在小屏幕上恢复占据 1 行
  }
}
</style>
